-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The Ultimate Way of Browsing Channels #1320
base: master
Are you sure you want to change the base?
Conversation
The script works extremely fast except the first time to update the whole data. It takes about 2 minutes to update the whole database with 80 different channels. You can set a cronjob for this. It's not a heavy work for the PC. It justs fetch the text data with yt-dlp. Video example below: This script is a sophisticated and ingenious tool designed to streamline your YouTube experience by organizing and managing your favorite YouTube channels, allowing you to browse and watch videos directly within the script without ever visiting its website. You can assign the channels inside various categories such as "Tech", "Science", "Sports", etc. The videos can be played using the 'mpv' media player. Moreover, the script allows you to sort videos based on view count or duration; download videos; and even maintain a "Watch Later" list. If you combine this script with "SponsorBlock" lua script created for "mpv", then you will have the ultimate experience. SponsorBlock removes all sponsored segments in a video including intros, outros or similar unnecessary parts. It's normally a browser extension but is also available for "mpv". No browsers, accounts, distractions, crappy algorithm and recommendations, advertisements, sponsors, intros, outros, fillers or empty spaces. We eliminate them all. Required Programs: dmenu | mpv | jq | yt-dlp FEATURES 1. Browse all videos from all channels you set at the same time. You can filter titles through dmenu. 2. Browse a channel's videos. 3. Select a channel either from the main menu or inside a Category. 4. Watch, Download or Put videos in a "Watch Later List". 5. Sort videos by view or duration. The default sort is upload date. The only problem is, we can't have the exact upload date, so we can't apply much more advanced filtering. It can be done but it makes fetching the data for the first time too slow. 6. The menus have a complex loop system. It always continues where you left off. The script doesn't close itself when you make a selection. So you don't have to run the script over and over again and get to where you left off. You can also press Escape to return to a prior menu. 7. You won't see the URLs or any unnecessary things inside dmenu. Just the titles. JUSTIFICATION This script is incredibly beneficial for those who seek a minimalist and focused approach to consuming content on YouTube. By providing a CLI-based interface (dmenu), the script reduces distractions and clutter that are commonly encountered on the Youtube website. It allows users to personalize their content consumption and manage channels more effectively. The script is also remarkably efficient and easy to navigate, providing a user-friendly experience that saves time and promotes productivity. The script is organized into functions that each perform a specific task, such as updating channel data, retrieving video titles, playing videos, downloading videos, adding videos to the watch later list, and browsing all channels. These functions are called by the main script to provide the user with various options for navigating and interacting with the videos. The script makes use of various Bash features such as associative arrays, shell redirection and piping, to simplify and streamline the code. It also uses conditionals and loops to handle different user input and error cases. Overall, this script is a powerful and flexible tool for browsing, watching, organizing YouTube channels, and it provides a great example of Bash usage to automate and streamline complex tasks. DETAILED EXPLANATION - The script begins by defining two associative arrays, CHANNELS and CATEGORIES, which store the YouTube channel names along with their respective URLs and categories. It then sets the directories for storing data and videos, and creates them if they do not already exist. - The 'update_data' function updates the metadata for a given channel, while the 'update_all_channels' function updates metadata for all channels. The metadata includes the video title, URL, view count, and duration, which are extracted using 'yt-dlp' and 'jq' utilities. - The 'get_videos' function retrieves the video titles from the metadata of a given channel, sorted by the specified criteria (if any). The 'video_url' function returns the URL of a video based on its title and channel name. The 'play_video' and 'download_video' functions use 'mpv' and 'yt-dlp', respectively, to play or download a video given its title and channel name. - The 'add_to_watch_later' function appends the video title and channel name to a watch later list, while the 'play_watch_later' and 'delete_from_watch_later' functions play a video from the list or remove it, respectively. - The 'get_all_videos' function retrieves all video titles from the metadata of all channels, sorted by the specified criteria. The 'browse_all_channels' function lets you browse through all channels and select a video to watch, download, or add to the watch later list. - The main part of the script first prompts the user to update the database of channels. If the user chooses to do so, the 'update_all_channels' function is called. The script then presents the user with options to browse all channels, browse channels by category, or browse the watch later list. The script loops through these options until the user decides to exit.
I first ran channel-refresh (as implied) I suggest a simple check, then creating it if it doesn't exist. I used this for On pressing all videos on dmenu, it showed on dmenu "Choose a Video or enter @@sv or @@sd" awaiting input and showed the following output on the terminal: Anyway, cool scripts, the concepts got me hyped enough to try all 3 of them hahaha |
Haha :) I know that Luke probably won't merge all of these but I think his viewers are interested in things like this in general so I thought it would have been a good idea to share some of my scripts here. That's probably why he doesn't close the PRs even though he didn't accept some of these. All of the pull request scripts work since I and some other friends consistently use them. I can help you fix the problems. The script works like this: You need yt-dlp to download videos and their metadata. You need jq because yt-dlp gives a JSON output so it's easy to manipulate the metadata with using the lightweight and fast jq. It's installed as a default in some distros but not for some others. Then you need to have file named: ~/.local/share/categories.txt: In that file we create categories like below: And we need channel URLs in the file named: "~/.local/share/channels.txt" and it's formatted as below: So when you run "channelrefresh" script at this point, you download the metadata of the channels inside (channels.txt) with their name and the URL. I generally put this script to boot time so every time I boot my PC, I get notified as to which channels get updated. So when channelrefresh operation is finished, you can run yt-browser script and see your channels and categories there. I hope this helps. If not, please contact again and I am sure we can make it work. By the way bookmark script is an extremely simple script and works as expected without a problem. It's impossible that it has serious technical problems. It just sends the URL to the browser as below: and if your URL has search in it it just adds your keyword at the end: So it's nothing crazy. For the adding, removing and editing we use very basic sed commands. So there is no way that this script can have serious technical problems :) It's not a rocket science. I can agree that it can be improved but for now adding more features than necessary is pointless. I once added a feature to use it as a URLBAR and it had a function to go to any URL even if it's not saved but then I thought it was pointless because we can just open the browser for it or use Vim extensions such as vimium-ff or vimvixen. |
@TheYellowArchitect EDIT: I have added robust error handling and improved the way it waits for the network. Please use the latest version. |
It works. Damn, it's amazing to watch youtube via mpv at any time (even added SponsorBlock you suggested). Thank you very very much. I didn't even use the latest version you uploaded, it seems like I simply lacked the proper data at Man this is incredible. I hope this gets merged. But I would like to mention minor suggestions which are so minor that they can be ignored since the functionality is solid:
I will definitely make use of this, will probably make Whether this gets merged or not (it's just 2 bin files, it would be a shame not to), I also suggest making it its own (AUR) package, for these benefits:
Cheers and thank you :) |
Edited/Updated the above text* |
I am glad you liked the script :) Your suggestions are pretty valid. They can easily be done. Please feel free to add anything so we can think about it. I will probably add your suggestions soon. I still suggest you to use the latest versions though. I added good improvements. You can add the script to boottime and get notified immediately. Since computers can't connect to the internet in a second, the script also waits for the network connection properly now by pinging the 9.9.9.9 domain (Quad9 DNS: A reliable, safe DNS provider). |
I have added all of your suggestions and made them even better. Do you have anything more to add?
Thanks for your testing and suggestions. Again, if you have any more suggestions, feel free to mention. |
Aside of the nitpick above, all the changes are great and much-needed. I have no more suggestions, you basically implemented them all in a single day! 🚀 |
I share these scripts for users on other distros. Explicit functions and variables help people easily change the features without specifically modifying lots of different places on scripts. For example below function:
You can easily change it to It's also same for INSTALLER variable. It can be It's better to be spooky and transparent instead of hiding things :) Since the same users can also see that the installer variable is just a pacman command. |
Sure, but this repo (Artix+LARBS) doesn't have
Same argument as above. This repo is meant for Artix/Arch, so it's Regardless, well done. This with newsboat is quite the combo for watching youtube without youtube :P |
Of course. I already use sudo pacman and dmenu for the PR on this repo but this repo and Luke's channel is popular enough so other people can also see and use the scripts. In fact I share the PR links with people in general so there are also non-larbs users looking at these. So the main aim is to create fast, minimal, portable, extensible and easily modifiable scripts. It's also a good practice that your scripts are mostly POSIX compliant and easily portable for users on on other systems such as BSD. That's why I also use /bin/sh instead of Bash along with other advantages of Dash. In my opinion the best thing about the script is that even though it's very minimal (6.8kb) it has features that native YouTube client doesn't have. For example you can't sort by duration on YouTube or you can't put subscribed channels into separate categories and you can't search among your subscriptions. We also do all of these without a browser and an account and SponsorBlock is the icing on the cake :) This script can be easily be integrated with fzf so it can also fetch thumbnails and do YouTube search with Python integration or even with curl maybe but I think it's beyond its purpose. The idea here is not creating a different YouTube client but an alternative way to change the habits. FYI sponsorblock.lua config file has a snippet below, make sure to select all categories. Not all of these are activated as a default:
|
You just keep on giving! |
I have to admit that is nice concept to watch videos using dmenu/rofi and data taken uding yt-dlp. :) Myself I use RRS reader (newsboat) for channels subscription and some script to get the older videos (then using nvim to manage/play them with mpv). |
Yes I also used Newsboat for that before. The main advantage of this method is that you can categorize channels and easily filter categories, channels, or all videos from all channels. You can search for keywords, sort by views or duration (duration sorting is not even possible on native YouTube). You can create and manage custom playlists with this and all of these are completely modular so you don't actually use the 334 lines of the script but you only interact with the functions you need. So, it's minimal, clean and fast :) The other advantage is that I get notified with every boot as below when a channel has new videos: |
Usually I stick to the creator channel and for that I find my method better. :) But I am different person, so I have a different needs. ;) But your script give me better ideas how to retreive the content using |
I update my scripts and I found strange that I am getting different results between my approach (using Here is how I am getting the list using
In the
So I ran the command like this: Then I run another script using your approach:
So I run this command like this: Then I compared the line count:
So I wrote small comparison script:
This showed me the 59 records difference:
I wonder why geting list of videos using the channel name vs using channel ID gives such difference? Channel ID I got using Kind regards, |
OK. I found that if you use the following url to get the list of videos, then you will get a complete list: I am not sure how you can get channel ID easily using yt-dlp. |
OK. Found it. You can use |
For these types of things you can check the yt-dlp community. Some of the data is not default. For example, in order to get video dates, you need to use this argument with yt-dlp: You can try the yt-dlp command individually to see the output then try piping it into jq. To be honest I have tried to remove jq too and use native text processing tools such as sed but it's nearly impossible because the structure of the website can change but jq as a native json processor can properly extract the related data in a faster and safer way even when the structure changes. You can extract any json data you want with jq.
For example the above command is pretty intuitive and gives us some necessary data then it converts it into a tab separated value so we can use cut to use those. We can cut the first field to see the titles, second; to open the video, and others to sort the videos properly. This message is a little bit late so I couldn't help with your actual question but I am glad that you found this inspirational :) I can still try helping if you come with anything new though. |
I forgot to add after the change from Bash to Dash I also simplified this: ~/.local/share/channels.txt looks like below:
Luke Smith=https://www.youtube.com/@LukeSmithxyz/videos
Mental Outlaw=https://www.youtube.com/@MentalOutlaw/videos
~/.local/share/categories.txt:
Tech=Luke Smith|Mental Outlaw
The script works extremely fast except the first time to update the whole data. It takes about 2 minutes to update the whole database with 80 different channels. This is parallel though, the biggest channel determines the total time. You can set a cronjob for this. It's not a heavy work for the PC. It justs fetch the text data with yt-dlp. Video example below:
This script is a sophisticated and ingenious tool designed to streamline your YouTube experience by organizing and managing your favorite YouTube channels, allowing you to browse and watch videos directly within the script without ever visiting its website. You can assign the channels with various categories such as "Tech", "Science", "Sports", etc. The videos can be played using the 'mpv' media player. Moreover, the script allows you to sort videos based on view count or duration; download videos; and even maintain a "Watch Later" list. If you combine this script with "SponsorBlock" lua script created for "mpv", then you will have the ultimate experience. SponsorBlock removes all sponsored segments in a video including intros, outros or similar unnecessary parts. It's normally a browser extension but is also available for "mpv".
No browsers, accounts, distractions, crappy algorithm and recommendations, advertisements, sponsors, intros, outros, fillers or empty spaces. We eliminate them all.
Video Example:
yt-browser.webm
Required Programs: dmenu | mpv | jq | yt-dlp
FEATURES
JUSTIFICATION
This script is incredibly beneficial for those who seek a minimalist and focused approach to consuming content on YouTube. By providing a CLI-based interface (dmenu), the script reduces distractions and clutter that are commonly encountered on the Youtube website. It allows users to personalize their content consumption and manage channels more effectively. The script is also remarkably efficient and easy to navigate, providing a user-friendly experience that saves time and promotes productivity.
The script is organized into functions that each perform a specific task, such as updating channel data, retrieving video titles, playing videos, downloading videos, adding videos to the watch later list, and browsing all channels. These functions are called by the main script to provide the user with various options for navigating and interacting with the videos.
The script makes use of various Bash features such as associative arrays, shell redirection and piping, to simplify and streamline the code. It also uses conditionals and loops to handle different user input and error cases. Overall, this script is a powerful and flexible tool for browsing, watching, organizing YouTube channels, and it provides a great example of Bash usage to automate and streamline complex tasks.
Why Does The Script Use "Bash"?(It works with Dash now)Associative arrays: Dash only supports indexed arrays, not associative arrays. The script uses associative arrays for both CHANNELS and CATEGORIES.
Indirect parameter expansion: The ${!array[@]} notation, which is used to get the keys of an associative array, is a Bash-specific feature.
declare command: The declare command is not available in Dash. In this script, it is used to define associative arrays.
To make the script compatible with Dash, you would need to replace the associative arrays with a compatible data structure or use separate indexed arrays for keys and values. You would also need to replace or modify the parts of the script that use indirect parameter expansion or the declare command. However, doing so might make the script more complex and harder to maintain.
DETAILED EXPLANATION